<html lang="zh-CN">
<head>
    <title>系统注册</title>
	<meta charset="utf-8">
    <style>
        div{
            width:400px;
            height:100px;
            position: absolute;
            top:50%;
            left:50%;
            margin-top: -50px ;
            margin-left:-150px;
        }
		input {
			 cursor: pointer;
			 width: 200px; 
			
		}
    </style>
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"/>	</script>
	<script>
		var flag = 1;  
		var i = 60;  
		function countDown() {  
			i = i - 1;  
			$("#span_id").html(i+"秒");  
			if (i == 0) {  
				$("#span_id").html('<a onclick="getCode()" href="#">获取验证码</a>');  
				flag = 1;  
				i = 60;  
				return;  
			}  
			setTimeout(countDown,1000);  
		} 


		function getCode(){
			var email = $("#email_id").val();
			if(!email){
				alert("请输入邮箱")
			}
			$.get("http://www.test.com:8000/api/code/create/"+email,function(data,status){
				console.log("数据: " + data + "\n状态: " + status);
				if(data){
					countDown()
				}
			});
		}
		
		function register(){
			var email = $("#email_id").val();
			var password = $("#password_id").val();
			var ConfirmPassword = $("#ConfirmPassword_id").val();
			
			if (password!=ConfirmPassword){
				alert("密码不一致");
				return;
			}
			
			var code = $("#code_id").val();
			$.get("http://www.test.com:8000/api/user/register/"+email+"/"+password+"/"+ code,function(data,status){
				console.log("数据: " + data + "\n状态: " + status);
				alert("注册成功");
				location.href="/static/login.html";
			}).error(function (data,status) {
				alert(data.responseJSON.message)
			})
		}	
	</script>
</head>
<body>
    <div>
        <form method="post" action="/login">
            <table>
                <tr>
                    <td>邮箱：</td>
                    <td><input type="text" id="email_id" name="email"></td>
                </tr>
                <tr>
                    <td>密码：</td>
                    <td><input type="password" id="password_id" name="password"> </td>
                </tr>
				<tr>
                    <td>确认密码：</td>
                    <td><input type="password" id="ConfirmPassword_id" name="ConfirmPassword"></td>
                </tr>
                <tr>
                    <td>验证码：</td>
                    <td><input style="width: 130px; "  id="code_id" type="text" name="code"><span id="span_id"><a onclick="getCode()" href="#">获取验证码</a></span> </td>
                </tr>
				
				<tr>
				 <td></td>
                    <td><input type="button" value="注册" onclick="register()"> </td>
                </tr>
            </table>

        </form>
    </div>
</body>
</html>
